﻿using System.Linq;
using ESoft.Core.Data.Service;
using ESoft.Core.Web.Utils;
using ESoft.Core.Web.VO;
using ESoft.Portal.Areas.SettingManager.Data.Service;
using ESoft.Portal.Data.Domain.Entity;
using Microsoft.AspNetCore.Mvc;

namespace ESoft.Portal.Areas.SettingManager.Rest
{
    [Route("api/setting")]
    public class SettingRestController : Controller
    {
        private readonly ISettingService _settingService;
        private readonly IBaseService _baseService;

        public SettingRestController(ISettingService settingService, IBaseService baseService)
        {
            _settingService = settingService;
            _baseService = baseService;
        }

        [Route("QueryBasic")]
        [HttpGet]
        public object QueryBasic()
        {
            User user = EnvUtils.GetCurrentUser(HttpContext);
            return ResponseResult.Success(_baseService.QueryEntities<UOrgEntity>(x => x.OrgId == user.ShopId).FirstOrDefault());
        }

        [Route("SaveBasic")]
        [HttpPost]
        public object SaveBasic([FromBody]dynamic dy)
        {
            User user = EnvUtils.GetCurrentUser(HttpContext);

            UOrgEntity org = _baseService.Find<UOrgEntity>(user.ShopId);
            string mobilePhone = dy.mobilePhone;
            string fax = dy.fax;
            string qqNum = dy.qqNum;
            string address = dy.address;
            string orgName = dy.orgName;

            org.MobilePhone = mobilePhone;
            org.Fax = fax;
            org.QqNum = qqNum;
            org.Address = address;
            org.OrgName = orgName;
            _baseService.Update(org);

            return ResponseResult.Success("保存成功");
        }
    }
}
